# This code was lifted from the instant-press application by Pablo Martin.
# Mucho hackyness modification where made by Christopher Steel of Voice of Access.
# Please address any issues with this application to Christopher.Steel@VoiceOfAcess.org
#
# The code remains:
# License: GPL, General Public License v.2
#
# Here is Pablo's Header from the original code.
#
# -*- coding: utf-8 -*-
# Instant Press, site that work out the box. Blog system for Web2py Framework 
# Site: http://www.instant2press.com
# Site: http://code.google.com/p/instant-press/
# Copyright (c) 2010- Mulone, Pablo Martín (mulone.martin@gmail.com)
# License: GPL, General Public License v.2
# Visit: www.web2py.com or Groups: http://groups.google.com/group/web2py and http://groups.google.com/group/web2py-usuarios  

import os
def _write_content(controller,function,arg,title,subtitle,view,format,lang,body,created_by):
    id_plugin_flatpage = db.plugin_flatpage.insert(controller=controller,
                                                    function=function,
                                                    arg=arg,
                                                    title=title,
                                                    subtitle=subtitle,
                                                    view=view,
                                                    format=format,
                                                    lang=lang,
                                                    body=body,
                                                    created_by=created_by)
    return id_plugin_flatpage
   
#if there are no plugin_flatpage pages then create some 
def _insert_flatpages_default_content():
    pagecount = db(db.plugin_flatpage.id>0).count() #GAE
    if pagecount <=0:

        controller  = 'plugin_flatpages'
        function    = 'index'
        arg         = request.args and request.args[0]

        #First post
        title       = 'flatpages plugin demo'
        subtitle    = 'an example of a flatpage using the content from this plugins about file'
        view        = FLATPAGE_VIEW
        format      = "MARKMIN"
        lang        = session._language
        file_path = os.path.join(cwd,'applications',request.application, 'static', plugin_name, 'DEMO')
        body        =open(file_path,'r').read()

#        created_on  = '2010-08-24 18:02:00'
        created_by = _fill_get_admin_guy()
              
        _write_content(controller,function,arg,title,subtitle,view,format,lang,body,created_by)
